<?php
    session_start();
	if($_SESSION['uid']==""||$_SESSION['level']!=2){
		header("Location: ./login.php");
		exit();
	}
	include('/php/tool/submitValidate.php');
    include('/php/tool/pdo.php');
    include('/php/bll/PublicDataBLL.php');
    include('/php/class/public-data.class.php');
    include('/php/class/student-information-register.class.php');
    include('/php/class/class-dormitory-management.class.php');
    include('/php/class/student-dormitory-allocating.class.php');
    include('/php/bll/StudentDormitoryAllocatingBLL.php');
    //
    $allocate = isset($_GET['allocate']) ? (int)$_GET['allocate'] : 0;
    $grade = isset($_GET['grade']) ? (int)$_GET['grade'] : 0;
    $major = isset($_GET['major']) ? (int)$_GET['major'] : 0;
    $class = isset($_GET['class']) ? $_GET['class']:0;
    $gender = isset($_GET['gender']) ? $_GET['gender']:0;
	$page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
	$pageSize = isset($_GET['pageSize']) ? (int)$_GET['pageSize'] : 20;
    $search = isset($_GET['search']) ? $_GET['search'] : '';
    
    $publicData=new PublicDataBLL();
    $StudentDormitoryAllocatingBLL=new StudentDormitoryAllocatingBLL();
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<script src="./scripts/crypto-js/core.js"></script>
<script src="./scripts/crypto-js/md5.js"></script>
<title>辅导员管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 宿舍管理 
	<span class="c-gray en">&gt;</span> 学生宿舍分配 
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
		<i class="Hui-iconfont">&#xe68f;</i>
	</a>
</nav>
<div class="page-container">
	<div class="cl pd-5 mybg-2 bk-gray"> 
		<span class="l"> 
			<a href="javascript:;" onclick="removeStudentDormitory()" class="btn btn-danger radius">
				<i class="Hui-iconfont">&#xe6e2;</i> 移除选中
			</a> 
		</span> 
		<span class="r">
			<button onclick="removeIframe()" class="btn btn-primary radius">关闭选项卡</button>
		</span>
	</div>
	<div class="mt-10">
        <label id="ttt"></label>
		<form action="student-dormitory-allocating.php" method="get" class="form-horizontal mybg-2 bk-gray pt-5 pb-5">
            <div class="row cl mb-5">
                <label class="form-label col-xs-1" style="width:100px;margin:0;padding:0;line-height:31px;">分配状态：</label>
				<div class="formControls col-xs-8 col-sm-2">
                    <select id="allocate_status" name="allocate" class="select" size="1" style="height:31px">
						<option value="0" <?php echo $allocate==0?'selected="selected"':'';?>>所有</option>
						<option value="1" <?php echo $allocate==1?'selected="selected"':'';?>>已分配</option>
						<option value="2" <?php echo $allocate==2?'selected="selected"':'';?>>未分配</option>
					</select>
					<input type="text" name="grade" value="<?php echo $grade;?>" class="input-text" style="display:none">
                </div>
				<div class="formControls col-xs-8 col-sm-3">
					<input type="text" value="<?php $majorName=$publicData->getMajorName($major); echo $majorName['major_name'];?>" class="input-text" style="display:none">
                    <input type="text" name="major" value="<?php echo $major;?>" class="input-text" style="display:none">
                    <input type="text" name="class" value="<?php echo $class;?>" class="input-text" style="display:none">
                </div>
            </div>
            <div class="row cl mb-5">
                <label class="form-label col-xs-1" style="width:100px;margin:0;padding:0;line-height:31px;">性别：</label>
				<div class="formControls col-xs-8 col-sm-2">
                    <select id="gender" name="gender" class="select" size="1" style="height:31px">
						<option value="0" <?php echo $gender==0?'selected="selected"':'';?>>所有</option>
						<option value="1" <?php echo $gender==1?'selected="selected"':'';?>>女生</option>
						<option value="2" <?php echo $gender==2?'selected="selected"':'';?>>男生</option>
					</select>
				</div>
				<label class="form-label col-xs-1" style="width:100px;margin:0;padding:0;line-height:31px;">学号或姓名：</label>
				<div class="formControls col-xs-8 col-sm-2">
					<input type="text" name="search" value="<?php echo $search;?>" class="input-text" placeholder="">
                </div>
                <button id="btn-search" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 查找</button>
			</div>
		</form>
	</div>
	<table class="table table-border table-bordered table-hover table-bg mt-10">
		<thead>
			<tr>
				<th scope="col" colspan="9">学生住宿管理</th>
			</tr>
			<tr class="text-c">
				<th width="25"><input type="checkbox" value="" name=""></th>
				<th width="180">学号</th>
				<th width="180">姓名</th>
                <th width="120">性别</th>
				<th width="120">年级</th>
                <th width="200">专业</th>
                <th width="200">班级</th>
                <th width="100">分配状态</th>
				<th width="70">操作</th>
			</tr>
		</thead>
		<tbody id="">
        <?php 
            $result=$StudentDormitoryAllocatingBLL->getStudentList($allocate,$grade,$major,$class,$gender,$search,$page,$pageSize);
            $studentList=$result['studentList'];
            foreach($studentList as $student){
                echo '<tr class="text-c"><td><input type="checkbox" value="'.$student['student_id'].'" name="student_checkbox"></td>
                <td class="student_id">'.$student['student_id'].'</td>
                <td class="name">'.$student['name'].'</td>
                <td class="gender">'.($student['gender']==1?'女':'男').'</td>
                <td class="grade">'.$student['grade'].'</td>
                <td class="major_name">'.$student['major_name'].'</td>
                <td class="class">'.$student['class'].'</td>
                <td class="allocate_status">'.($StudentDormitoryAllocatingBLL->isStudentDormitory($student['student_id'])==1?'已分配':'未分配').'</td>
                <td><a title="编辑" href="javascript:;" onclick="dormitory_view(this,\''.$student['student_id'].'\')" style="text-decoration:none">
                <i class="Hui-iconfont">&#xe6df;</i></a>
                <a title="删除" href="javascript:;" onclick="removeStudent(this,\''.$student['student_id'].'\')" class="ml-5" style="text-decoration:none">
				<i class="Hui-iconfont">&#xe6e2;</i></a></td></tr>';
            }
        ?>
		</tbody>
	</table>
	<div class="modal-footer">
		<a class="btn" href="<?php echo 'student-dormitory-allocating.php?allocate='.$allocate.'&grade='.$grade.'&major='.$major.'&class='.$class.'&gender='.$gender.'&sreach='.$search.'&page='.($page-1>0?$page-1:0).'&pageSize='.$pageSize;?>">上一页</a>
			<span><select  id="jump_page" name="page" class="btn">
                    <?php
                        $pageMax=$result['count'];
                        if($pageMax>0){
                            for($i=0;$i<$pageMax;$i++){
                                if($i==$page){//selected=""
                                    echo '<option value="'.$i.'" selected="selected">'.($i+1).'</option>';
                                }else{
                                    echo '<option value="'.$i.'" ">'.($i+1).'</option>';
                                }
                            }
                        }else{
                            echo '<option value="0">1</option>';
                        }
                    ?>
			</select>
		</span>
		<a class="btn" href="<?php echo 'student-dormitory-allocating.php?allocate='.$allocate.'&grade='.$grade.'&major='.$major.'&class='.$class.'&gender='.$gender.'&sreach='.$search.'&page='.($page+1<$pageMax?$page+1:$page).'&pageSize='.$pageSize;?>">下一页</a>
	</div>
</div>

<!-- 宿舍列表 -->
<div id="modal-dormitory-view" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" style="width:80%;">
			<div class="modal-content radius">
				<div class="modal-header">
					<h3 class="modal-title">宿舍列表</h3>
					<a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
				</div>
				<div class="modal-body">
                <input type="text" id="dormitory_student_id" value="" class="input-text" style="display:none">
                <input type="text" id="dormitory_gender" value="" class="input-text" style="display:none">
					<div class="mt-10">
                        <table class="table table-border table-bordered table-hover table-bg mt-10">
                            <thead>
                                <tr>
                                    <th scope="col" colspan="6">宿舍列表</th>
                                </tr>
                                <tr class="text-c">
                                    <th >公寓名称</th>
                                    <th >楼层</th>
                                    <th >宿舍编号</th>
                                    <th >分类</th>
                                    <th >空床位</th>
                                    <th width="70">操作</th>
                                </tr>
                            </thead>
                            <tbody id="dormitory_list">
                                <?php
                                    $dormitoryList=$StudentDormitoryAllocatingBLL->getDormitoryList($_SESSION['uid'],$grade,$major,$gender);
                                    foreach($dormitoryList as $dormitory){
                                        echo '<tr class="text-c">
                                        <td class="apartment_id" style="display:none">'.$dormitory['apartment_id'].'</td>
                                        <td class="apartment_name">'.$dormitory['apartment_name'].'</td>
                                        <td class="floor">'.$dormitory['floor'].'</td>
                                        <td class="dormitory_id">'.$dormitory['dormitory_id'].'</td>
                                        <td class="property">'.($dormitory['property']==1?'女生宿舍':'男生宿舍').'</td>
                                        <td class="beds">'.($dormitory['beds']-$StudentDormitoryAllocatingBLL->getAllocatedBedsNumber($dormitory['apartment_id'],$dormitory['dormitory_id'],$grade,$major)).'</td>
                                        <td><input type="checkbox" value="'.$dormitory['apartment_id'].'" name="dormitory_checkbox"></td></tr>';
                                    }
                                ?>
                                
                            </tbody>
                        </table>
						<div class="modal-footer mybg-2">
							<button id="add" onclick="allocatingDormitory()" class="btn btn-primary radius">添加</button>
							<button class="btn btn-default radius" data-dismiss="modal" aria-hidden="true">取消</button>
						</div>
					</div>
				</div>
			</div>
		</div>
</div>
</body>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="scripts/student-dormitory-allocating.jquery.js"></script>
</body>
</html>